// video.c
#include <stdarg.h>
#include "math.h"
#include "ports.h"
#include "video.h"
#include "cursorctrl.h"
unsigned char *videoram = (unsigned char *) 0xB8000;
void clrscr()
{
  loc = 0;
  while (loc <= HEIGHT * WIDTH)
  {
    printc(0);
  }
  loc = 0;
  outb(0x3D4, 14);
  outb(0x3D5, loc >> 8);
  outb(0x3D4, 15);
  outb(0x3D5, loc);
//  updatexy();
}
void bk()
{
  loc--;
  videoram[loc] = 0;
  loc--;
  videoram[loc] = 0;
//  updatexy();
}
void printc(char c)
{
  videoram[loc] = c;
  loc++;
  videoram[loc] = 0x07;
  loc++;
  outb(0xE9, c);
}
void printca(char c, char att)
{
  videoram[loc] = c;
  loc++;
  videoram[loc] = att;
  loc++;
}
void print(char in[])
{
  char *ramloc = (char *) &in[0];
  while(*ramloc != 0)
  {
    printc(*ramloc);
    ramloc++;
  }
}
void printa(char in[], char att)
{
  char *ramloc = (char *) &in[0];
  while(*ramloc != 0)
  {
    printca(*ramloc, att);
    ramloc++;
  }
}
void ascii_test()
{
  int loop = 0;
  while(loop < 0xFF)
  {
    printc(loop);
    loop++;
  }
}
void special(char c)
{
  printc(c + '0');
}
void printint(int in)
{
  int buff_loc = 11;
  int digit;
  char buffer[11];
  if(in < 0)
  {
    in = -in;
    buffer[11] = "-";
    buff_loc--;
  }
  else
    buff_loc--;
  while(in)
  {
    digit = in % 10;
    in /= 10;
    printc(digit + "0");
  }
}